
let { Sandbox } = require('@e2b/code-interpreter')

const sandboxTimeout = 10 * 60 * 1000 // 10 minute in ms

var userID = '321431'

// e2b-key
var apiKey = 'e2b_16fe6f8b4754ee3be63624c78f4384c551420054'

var fragment = {
    "commentary": "I will create a simple Next.js 13+ application using the pages router. The application will display a welcome message on the homepage. This will be implemented in the pages/index.tsx file. The application will use Tailwind CSS for styling, which is already included in the template dependencies. No additional dependencies are required for this basic setup.",
    "template": "nextjs-developer",
    "title": "Welcome Page",
    "description": "A simple Next.js app displaying a welcome message.",
    "additional_dependencies": [],
    "has_additional_dependencies": false,
    "install_dependencies_command": "",
    "port": 3000,
    "file_path": "pages/index.tsx",
    "code": "import React from 'react';\n\nconst HomePage: React.FC = () => {\n  return (\n    <div className=\"flex items-center justify-center min-h-screen bg-gray-100\">\n      <h1 className=\"text-4xl font-bold text-blue-600\">Welcome to Next.js!</h1>\n    </div>\n  );\n};\n\nexport default HomePage;"
}

async function main() {

 // Create a interpreter or a sandbox
 const sbx = await Sandbox.create(fragment.template, {
    metadata: { template: fragment.template, userID: userID },
    timeoutMs: sandboxTimeout,
    apiKey,
  })

  var rs = JSON.stringify({
    sbxId: sbx?.sandboxId,
    template: fragment.template,
    url: `https://${sbx?.getHost(fragment.port || 80)}`,
  })
  
  console.log(rs)
}

main()
